package cn.core.act.rest;

import lombok.extern.log4j.Log4j2;
import org.springframework.context.annotation.Scope;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.Duration;

/**
 * cs REST API
 */
@Log4j2
@RestController
@Scope("prototype")
@RequestMapping("cs/redis")
public class CsRedisController {

  @Resource
  private StringRedisTemplate stringRedisTemplate;

  /**
   * cs
   * http://127.0.0.1:6660/api/cs/redis/cs
   * @return 返回
   */
  @GetMapping("cs")
  public String cs() throws Exception {
    try {
//      stringRedisTemplate.opsForValue().set("qwe", "wwwwwwwwwww", Duration.ofMillis(10000));
//      stringRedisTemplate.delete("key");
//      String value = stringRedisTemplate.opsForValue().get("qwe");
//      System.out.println(value);
//      stringRedisTemplate.opsForValue().set("qwe", "wwwwwwwwwww");
//      stringRedisTemplate.expire("qwe", Duration.ofMillis(10000));
    } catch (Exception e) {
      if (log.isDebugEnabled()) {
        log.error(e.getMessage(), e);
      }
      throw e;
    }
    return "";
  }

}
